//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define lson i<<1
#define rson i<<1|1
int L,T,O;
const int N=1e6+50;
struct node{
    int l,r,flag;
    //每种颜色的01向量进行状态压缩
    int color;
}tree[4*N];
void pushup(int i){
    tree[i].color=tree[lson].color|tree[rson].color;
}
void build(int i,int l,int r){
    tree[i].l=l;
    tree[i].r=r;
    tree[i].flag=0;
    if(l==r){
        tree[i].color=1;
        return;
    }
    int m=(l+r)>>1;
    build(lson,l,m);
    build(rson,m+1,r);
    pushup(i);
}
void pushdown(int i){
    if(tree[i].flag && tree[i].l!=tree[i].r){
        tree[lson].flag=tree[rson].flag=tree[i].flag;
        tree[lson].color=tree[rson].color=(1<<(tree[i].flag-1));
        tree[i].flag=0;
    }
}
void update(int i,int x,int y,int c){
    int l=tree[i].l,r=tree[i].r,m=(l+r)>>1;
    if(x==l && r==y){
        //整个区间涂成c
        tree[i].color=(1<<(c-1));
        //printf("%d\n",tree[i].color);
        tree[i].flag=c;
        return;
    }
    pushdown(i);
    if(y<=m){
        update(lson,x,y,c);
    }else if(x>m){
        update(rson,x,y,c);
    }else{
        update(lson,x,m,c);
        update(rson,m+1,y,c);
    }
    pushup(i);
}
int query(int i,int x,int y){
    int l=tree[i].l,r=tree[i].r,m=(l+r)>>1;
    if(l==x && r==y){
        return tree[i].color;
    }
    pushdown(i);
    if(y<=m){
        return query(lson,x,y);
    }else if(x>m){
        return query(rson,x,y);
    }else{
        return query(lson,x,m)|query(rson,m+1,y);
    }
}
int bit_count(int x){
    int ans=0;
    while(x){
        if(x&1){
            ans++;
        }
        x>>=1;
    }
    return ans;
}
int main(void){
    scanf("%d%d%d",&L,&T,&O);
    build(1,1,L);
    while(O--){
        char op[2];
        int a,b,c;
        scanf("%s",op);
        if(op[0]=='C'){
            scanf("%d%d%d",&a,&b,&c);
            if(a>b){
                swap(a,b);
            }
            update(1,a,b,c);
        }else{
            scanf("%d%d",&a,&b);
            if(a>b){
                swap(a,b);
            }
            int ans=query(1,a,b);
            printf("%d\n",bit_count(ans));
        }
    }
    return 0;
}